package top.ddandang.blog.controller;


import top.ddandang.blog.bean.GlobalResponse;
import top.ddandang.blog.model.vo.StatisticVo;
import top.ddandang.blog.service.ArticleService;
import top.ddandang.blog.service.StatisticsService;
import top.ddandang.blog.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author D
 * @since 2020-06-23
 */
@Slf4j
@RestController
@RequestMapping("/statistics")
public class StatisticsController {

    @Resource
    private StatisticsService statisticsService;

    @Resource
    private UserService userService;

    @Resource
    private ArticleService articleService;


    @GetMapping("/getTotalStatistics")
    public GlobalResponse getTotalStatistics () {
        StatisticVo statisticVo = statisticsService.getTotalStatistics();
        if(statisticVo.getTotalUser() == -1) {
            statisticVo.setTotalUser(userService.getUserAmount());
        }
        if (statisticVo.getTotalArticle() == -1) {
            statisticVo.setTotalArticle(articleService.getArticleCount());
        }
        return GlobalResponse.success().data("statisticVo", statisticVo);
    }
}

